package com.javaweb.controller;
import com.javaweb.dao.TagDao;
import com.javaweb.model.Tag;
import com.javaweb.service.dto.TagDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.javaweb.common.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc:
 * @author: jzy
 * @date: 2024/10/22 23:01
 */
/**
 * todo: 标签管理模块
 */
@RestController
@RequestMapping("/blog-api/v0.1/tag")
public class TagController {
private TagDao tagService;
    @GetMapping("/list")
    public ResponseResult<List<Tag>> list() {
        // 列出所有标签

        List<Tag> tags = tagService.findAllTags();
        return  ResponseResult.ok(tags);
    }

    @PostMapping("/add")
    public ResponseEntity<Integer> add(@RequestBody TagDto tagDto) {
        int createdTag = tagService.addTag(tagDto);
        return ResponseEntity.ok(createdTag);
    }

    @GetMapping("/delete")
    public ResponseResult<Void> delete(@RequestParam String tagId) {
        // 删除指定标签
        tagService.deleteTag(tagId);
        return ResponseResult.ok(null);
    }
}
